<?php
require_once 'CMS/Util.php';
require_once 'CMS/User.php';
require_once 'CMS/Mvc/BaseController.php';
require_once 'CMS/Mvc/BaseAdminController.php';
require_once 'CMS/AdminCommon.php';

//Người tạo : Nguyễn Thanh Hải - Team 2
//Module 	: UnInstall Widget
//Chức năng	: Xử lý việc uninstall các widget


class Admin_UnInstallWidgetController extends BaseAdminController {
		
	public function init(){
		parent::init();
		$this->_helper->layout()->setLayout('layoutadmin');
		$user = new User();
		$user->init();
		$user->check_login();
		$user->permission();
	}
	
	//Xử lý uninstall các widget bằng xmlhttp
	public function sidebarAction(){
		$user = new User();
		$user->init();
		$user->check_login();
		$hasmodify = $user->modifiy("admin/module");
		if($hasmodify==true)
		{
			$hasmodifywidget=$user->modifiy_widget($_GET["module"]);
			if($hasmodifywidget=="true")
			{
				if(isset($_GET["module"]))
				{
					$tbSidebarModule = new Admin_Model_SidebarModule();
					$tbSidebarModule->deleteModuleByCode($_GET["module"]);
					$data = 1;
				}
				else 
				{
					$data = -1;
				}
			}
			else $data = -2;
		}
		else $data = -2;
		$this->_helper->json($data); 
	}
	public function editpageAction(){
		
		if(isset($_GET['page']) && $_GET['page']!=null && $_GET['page']!="")
		{
			$tbCurrentPage = new Admin_Model_CurrentPage();
			$is_page = $tbCurrentPage->selectPageByCode($_GET['page']);
			if(count($is_page)>0)
			{
				if(isset($_GET["module"]))
				{
					$page = $is_page[0]['page_code'];
					$tbContentModule = new Admin_Model_ContentModule();
					$tbContentModuleToPage = new Admin_Model_ContentModuleToPage();
					$tbContentModule->deleteModuleByCode($_GET["module"]);
					$tbContentModuleToPage->deleteModuleByCode($_GET["module"],$page);
					$data = 1;
				}
				else 
				{
					$data = -1;
				}
			}
		}
		$this->_helper->json($data); 
	}
}